package cn.edu.eight.food.controller;


import cn.edu.eight.food.model.OfCategory;
import cn.edu.eight.food.service.ofCategoryService;
import cn.edu.eight.food.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/category")
public class ofCategoryController {
    @Autowired
    ofCategoryService ofCategoryService;

    @RequestMapping("/categoryList")
    @ResponseBody
    public Result ofCategoryList(String categoryName){
        List<OfCategory> categoryList = ofCategoryService.ofCategoryList(categoryName);
        Result<OfCategory> categoryResult = new Result<>();
        if (categoryList != null && categoryList.size() > 0 ){
            categoryResult.setCode("200");
            categoryResult.setMsg("请求成功");
            categoryResult.setCount(categoryList.size());
            categoryResult.setData(categoryList);
        }else {
            categoryResult.setCode("500");
            categoryResult.setMsg("没有数据！");
        }
        return categoryResult;
    }
}
